package com.appkubes.mall.restful.application.goods.sku.service.impl;

import com.appkubes.mall.core.entity.MallSpecificType;
import com.appkubes.mall.core.service.impl.BaseMallSpecificTypeServiceImpl;
import com.appkubes.mall.restful.application.goods.sku.dao.SpecificTypeDao;
import com.appkubes.mall.restful.application.goods.sku.service.SpecificTypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecificTypeServiceImpl extends BaseMallSpecificTypeServiceImpl implements SpecificTypeService {

    @Autowired
    SpecificTypeDao specificTypeDao;

    public List<MallSpecificType> getList(String appKey, String key) {
        QueryWrapper<MallSpecificType> query = new QueryWrapper<>();

        MallSpecificType entity = new MallSpecificType();
        entity.setTemplateKey(key);

        query.setEntity(entity);
        query.orderByDesc("specific_index");
        return this.getBaseMapper().selectList(query);
    }

    public MallSpecificType findByPluginCode(String templateKey, String code) {
        MallSpecificType entity = new MallSpecificType();
        entity.setPluginRef(code);
        entity.setTemplateKey(templateKey);

        List<MallSpecificType> specificTypeList = this.selectListByEntity(entity);
        if (specificTypeList.size() == 0) return null;
        return specificTypeList.get(0);
    }
}
